<template>
    <div>
        <Search :queryParams="queryParams" @formCommHandler='formCommHandler' style="max-height:210px;overflow-y:auto;">
            <template #search_after>
                <slot name="search_after_son"></slot>
            </template>
        </Search>  
        <edit-table v-bind="tableParams" ref="table">
            <template #table_before>
                <slot name="table_before_son"></slot>
            </template>
            <template #table_after>
                <slot name="table_after_son"></slot>
            </template>
        </edit-table>
    </div>
</template>
<script>
import Search from '@/components/baseComponents/Search'
import EditTable from '@/components/baseComponents/EditTable'
export default {
    name: 'EditTemplate',
    props: {
        tableParams: {
            type: Object,
            default: () => {}
        },
        queryParams: {
            type: Object,
            default: () => {}
        }
    },
    components: {
        Search,
        EditTable
    },
    mounted() {
    },
    methods: {
        formCommHandler(data) {
            let _this = this
            if(data.type == "search"){ //查询
                new Promise((resolve,reject)=>{
                    _this.$emit('formCommHandler', data)
                    resolve()
                }).then(()=>{
                    _this.$refs['table'].query(_this.queryParams.queryData);
                })
            }
            else{
                _this.$emit('formCommHandler', data)
            }
            
            if(data.type == "add"){ //新增
                let obj = JSON.parse(JSON.stringify(_this.tableParams.rowDataJson));
                if(obj){
                    _this.$refs.table.addRow(obj);
                }
            }
            
            if(data.type == "save"){ //保存
                _this.$emit('saveHandler',_this.$refs.table.saveData)
            }
            
            if(data.type == "del"){ //删除
                new Promise((resolve,reject)=>{
                    _this.$emit('delHandler$before',_this.$refs.table.saveData)
                    resolve()
                }).then(() => {
                    _this.$refs.table.deleteRow()
                }).then(() => {
                    _this.$emit('delHandler$after',_this.$refs.table.saveData)
                })
            }
        }
    }
}
</script>
<style>

</style>


